﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;

namespace ERP_RORZE.Product.MO
{
    public partial class frm_MOMaterialAdd : DevExpress.XtraEditors.XtraForm
    {
        ClsMODAO clsMODAO = new ClsMODAO();
        ClsPartDataDAO clsPart = new ClsPartDataDAO();
        ClsMaterialDAO clsMaterialDAO = new ClsMaterialDAO();
        DataTable dt;
        ClsMOMaterialTable b = new ClsMOMaterialTable();
        
        public event EventHandler Reload;

        public frm_MOMaterialAdd()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frm_MOMaterialAdd_Load(object sender, EventArgs e)
        {
            //
            dt = clsMODAO.GetAllMO();
            cbMONo.DataSource = dt;
            cbMONo.DisplayMember = "MONo";
            cbMONo.ValueMember = "MONo";
            //

            dt = clsPart.GetAllPartID();
            cbPartID.DataSource = dt;
            cbPartID.DisplayMember = "PartNo";
            cbPartID.ValueMember = "PartNo";
            //

            dt = clsMaterialDAO.GetAllMaterial();
            cbMaterial.DataSource = dt;
            cbMaterial.DisplayMember = "MaterialID";
            cbMaterial.ValueMember = "MaterialID";
            
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtCutSize.Text == "")
            {
                MessageBox.Show("Chưa nhập CutSize");
            }
            else if (txtlenght.Text == "")
            {
                MessageBox.Show("Chưa nhập Lenght");
            }
            else if (txtMaterialPrice.Text == "")
            {
                MessageBox.Show("Chưa nhập MaterialPrice");
            }
            else if (txtMaterialType.Text == "")
            {
                MessageBox.Show("Chưa nhập MaterialType");
            }
            else if (txtPrice.Text == "")
            {
                MessageBox.Show("Chưa nhập Price");

            }
            else if (txtShape.Text == "")
            {
                MessageBox.Show("Chưa nhập Shape");
            }
            else if (txtThickness.Text == "")
            {
                MessageBox.Show("Chưa nhập Thickness");

            }
            else if (txtwidth.Text == "")
            {
                MessageBox.Show("Chưa nhập Width");
            }
            else
            {
                b.CutSize = txtCutSize.Text;
                b.Finishdate = dateFinishdate.Value;
                b.Finished = checkFinished.Checked;
                b.Lenght = float.Parse(txtlenght.Text);
                b.MaterialID = cbMaterial.Text;
                b.MaterialPrice = int.Parse(txtMaterialPrice.Text);
                b.MaterialType = txtMaterialType.Text;
                b.Note = txtNote.Text;
                b.MONo = cbMONo.Text;
                b.PartID = cbPartID.Text;
                b.Price = int.Parse(txtPrice.Text);
                b.Shape = txtShape.Text;
                b.Thickness = float.Parse(txtThickness.Text);
                b.Width = float.Parse(txtwidth.Text);
                clsMODAO.InsertMOMaterial(b);
                Reload(sender, e);
            }
        }
    }
}